package com.sc.nft.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sc.nft.dao.OfficialWebsiteArticleDao;
import com.sc.nft.entity.OfficialWebsiteArticle;
import com.sc.nft.entity.dto.OfficialWebsiteArticleAdminAddDTO;
import com.sc.nft.entity.vo.OfficialWebsiteArticleAdminUpdateDTO;
import com.sc.nft.entity.vo.OfficialWebsiteArticleAdminVO;
import com.sc.nft.entity.vo.OfficialWebsiteArticleWebVO;
import com.sc.nft.service.OfficialWebsiteArticleService;
import com.sc.nft.sup.PageRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 官网文章(OfficialWebsiteArticle)表服务实现类
 *
 * @author wwc
 * @since 2023-08-09 17:37:06
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class OfficialWebsiteArticleServiceImpl implements OfficialWebsiteArticleService {

    private final OfficialWebsiteArticleDao officialWebsiteArticleDao;

    @Override
    public IPage<OfficialWebsiteArticleWebVO> pageWeb(PageRequest pageRequest) {
        return officialWebsiteArticleDao.pageWeb(pageRequest.toMp()).convert(officialWebsiteArticle -> {
            OfficialWebsiteArticleWebVO officialWebsiteArticleWebVO = new OfficialWebsiteArticleWebVO();
            BeanUtil.copyProperties(officialWebsiteArticle, officialWebsiteArticleWebVO);
            return officialWebsiteArticleWebVO;
        });
    }

    @Override
    public IPage<OfficialWebsiteArticleAdminVO> pageAdmin(PageRequest pageRequest) {
        return officialWebsiteArticleDao.pageWeb(pageRequest.toMp()).convert(officialWebsiteArticle -> {
            OfficialWebsiteArticleAdminVO officialWebsiteArticleAdminVO = new OfficialWebsiteArticleAdminVO();
            BeanUtil.copyProperties(officialWebsiteArticle, officialWebsiteArticleAdminVO);
            return officialWebsiteArticleAdminVO;
        });

    }

    @Override
    public void update(OfficialWebsiteArticleAdminUpdateDTO officialWebsiteArticleAdminUpdateDTO) {
        officialWebsiteArticleDao.updateById(BeanUtil.copyProperties(officialWebsiteArticleAdminUpdateDTO, OfficialWebsiteArticle.class));
    }

    @Override
    public void deleteById(Long id) {
        officialWebsiteArticleDao.removeById(id);
    }

    @Override
    public void add(OfficialWebsiteArticleAdminAddDTO officialWebsiteArticleAdminAddDTO) {
        officialWebsiteArticleDao.save(BeanUtil.copyProperties(officialWebsiteArticleAdminAddDTO, OfficialWebsiteArticle.class));
    }

}
